﻿var AuditReasonVm = function (jsonOfObject) {
    var self = this;
    self.IsEnabled = ko.observable(false);

    self.Refresh = function (jsonData) {
        ko.mapping.fromJS(jsonData, {}, self);
    };

    if (jsonOfObject === undefined) {
        self.Id = ko.observable(null);
        self.Title = ko.observable(null).extend({
            trimString: null,
            required: { message: "Title is a required field.", params: true },
            maxLength: { message: "Please enter less than 50 characters.", params: 50 },
            pattern: { message: "Numeric and Special Characters are not allowed.", params: '^[a-zA-Z ~/-]+$' }
        });

        self.Description = ko.observable(null).extend({
            trimString: null,
            required: {message: "Description is a required field.", params: true },
            maxLength: { message: "Please enter less than 250 characters.", params: 250 },
            pattern: { message: "Special Characters are not allowed.", params: '^[a-zA-Z0-9 ~/-]+$' }
        });

        self.IsEnabled(false);

    } else {
        self.OriginalJsonOfObject = jsonOfObject;
        self.IsEnabled(true);
        self.Refresh(jsonOfObject);
    }

    self.Clone = function () {
        var reason = new AuditReasonVm(self.OriginalJsonOfObject);
        return reason;
    };

};
